package com.pqtest.api.dto;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.pqtest.api.entity.ConnectionEntity;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
public class SimulibraryReportDto {
    @JsonProperty("right_rate")
    private int rightRate;
    @JsonProperty("spent_time")
    private int spentTime;
    @JsonProperty("pass_over")
    private int passOver;
    @JsonProperty("detail")
    private Map<String,List<ConnectionDto>> detail;
    @JsonProperty("detail_rate")
    private Map<String,Integer>detailRate;

    public Object viewTransform(){
        JSONObject result = new JSONObject();
        result.put("right_rate",this.getRightRate());
        result.put("spent_time",this.getSpentTime());
        result.put("pass_over",this.getPassOver());
        //result.put("detail",this.getDetail());
        List<Map<String,Object>> detail = new ArrayList<>();
        this.getDetail().forEach((k,v)->{
            Map<String,Object> item = new HashMap<>();
            item.put("point_title",k);
            BigDecimal bd = new BigDecimal(((float)this.getDetailRate().get(k)/v.size()) * 100);
            bd = bd.setScale(0,BigDecimal.ROUND_HALF_UP);
            item.put("right_rate",bd.intValue());
            item.put("subjects",v);
            detail.add(item);
        });
        result.put("detail",detail);
        return result;
    }
}

